package org.csu.mypetstore.api.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.csu.mypetstore.api.vo.ChatUserVO;
import org.csu.mypetstore.api.vo.MessageVO;

import java.util.Date;

@Data
@TableName("message")
public class Message {
    @TableId(value = "id",type = IdType.INPUT)
    private String id;
    private String status;
    private String type;
    @TableField(value = "sendTime")
//    private String sendTime;            //前端生成的时间以字符串形式储存
    private Date sendTime;
    @TableField(value = "toContactId")
    private String toContactId;         //信息接收方
    @TableField(value = "fromUserId")
    private String fromUserId;          //信息发送表
    private String content;             //消息内容

    public MessageVO toVO(Message message,ChatUserVO userVO){
        MessageVO vo = new MessageVO();
        vo.setId(message.getId());
        vo.setStatus(message.getStatus());
        vo.setType(message.getType());
        vo.setSendTime(message.getSendTime());
        vo.setContent(message.getContent());
        vo.setToContactId(message.getToContactId());
        vo.setFromUser(userVO);

        return vo;
    }

    public static Message toMessage(MessageVO vo){
        Message message = new Message();
        message.setId(vo.getId());
        message.setStatus(vo.getStatus());
        message.setType(vo.getType());
        message.setSendTime(vo.getSendTime());
        message.setToContactId(vo.getToContactId());
        message.setFromUserId(vo.getFromUser().getId());
        message.setContent((String)vo.getContent());        //目前仅支持String的消息

        return message;
    }
}
